home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / DNA_XCMD / REVERSEC.C < prev   
C/C++ Source or Header  |  1991-09-14  |  2KB  |  49 lines

  1. /*    ReverseCompliment.c
  2.     
  3.     A HyperCard XFCN that returns the reverse (backwards) complimented sequence.  It
  4.     uses the base conversion routine 'BaseComp.c' to map the individual bases.
  5.     
  6.     Molecular Genetics Laboratory, The Salk Institute
  7.     Division of Biology & Dept. of Comp. Sci, Washington University
  8.     America OnLine: Reece            Internet: reece@informatics.wustl.edu
  9.     
  10.     To compile (Think C):
  11.         1) Create project with this file, BaseComp.c, MacTraps, ANSI-A4, and HyperXLib.
  12.         2) Choose 'Set Project Type╔'. Select type 'Code Resource',
  13.             name 'ReverseCompliment', type 'XFCN', and ID '2002'.
  14.         3) Select 'Build Code Resource╔" from Project menu.
  15. */
  16.  
  17. #include <HyperXCmd.h>
  18. #include "string.h"
  19. #include "BaseComp.h"
  20.  
  21. #define        NIL        ((void *) 0)
  22.  
  23. pascal    void    main(XCmdPtr  paramPtr)
  24. {
  25.     Handle                ReturnHdl;
  26.     register    char    *i, *j;        /* i will point to incoming, j to outgoing        */
  27.     int                    len;
  28.     
  29.     /*    Get length of incoming sequence                                                */
  30.     len = strlen(*paramPtr->params[0]);
  31.  
  32.     /*    Allocate space that is as large as the incoming sequence + 1 for '\0'.  If
  33.         allocation fails, we return a NIL handle.                                    */
  34.     if ( (ReturnHdl = (Handle) NewHandle ((long) len + 1)) != NIL )
  35.         {
  36.         /*    Incoming sequence (i) will be read left to right until '\0', and stored
  37.             in outgoing sequence (j) from right to left.                            */
  38.         i = *paramPtr->params[0];    /*    i points to start of incoming                */
  39.         j = *ReturnHdl + len;        /*    and j points to end of outgoing                */
  40.         
  41.         *j-- = '\0';                /*    null terminate outgoing and decrement j        */
  42.         
  43.         for ( ; *i; i++, j--)        /*    copy sequence in reverse                    */
  44.             *j = BaseCompliment(*i);
  45.         }
  46.  
  47.     paramPtr->returnValue = ReturnHdl;
  48. }
  49.